package leecode

import "sort"

func minStartValue(nums []int) (result int) {
	prefix := make([]int, len(nums)+1)
	for i := 0; i < len(nums); i++ {
		prefix[i+1] = prefix[i] + nums[i]
	}
	//求得前缀和中最小的值
	sort.Ints(prefix)
	if prefix[0] > 0 {
		return prefix[0]
	} else {
		result = -prefix[0] + 1
	}
	return
}
